package cn.xyinping._01_hello;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 27266
 * @desrciption
 * @date 2021/11/12
 */
public class Producer {
    // 队列名
    public static final String QUEUE = "helloWord";
    public static void main(String[] args) throws IOException, TimeoutException {
        // 1. 创建RabbitMQ链接
        ConnectionFactory factory  = new ConnectionFactory();
       /* factory.setUsername(userName);
        factory.setPassword(password);
        factory.setVirtualHost(virtualHost);
        factory.setHost(hostName);
        factory.setPort(portNumber);*/
        Connection connection = factory.newConnection();
        // 2. 创建通道
        Channel channel = connection.createChannel();
        // 3. 创建队列
    /*    @param queue the name of the queue 队列名
     * @param durable true if we are declaring a durable queue (the queue will survive a server restart) 队列持久化
     * @param exclusive true if we are declaring an exclusive queue (restricted to this connection) 队列独占链接
     * @param autoDelete true if we are declaring an autodelete queue (server will delete it when no longer in use) 用完是否删除
     * @param arguments other properties (construction arguments) for the queue  其他配置*/
        channel.queueDeclare(QUEUE, // 队列名
                true, // 队列持久化
                false, // 队列独占链接
                false,// 用完是否删除
                null); // 其他配置
        // 4. 发送消息
        channel.basicPublish("", // 使用默认交换机
                QUEUE, // 队列名
                null, // 其他参数
                "大海我来了！".getBytes()); // 要发送的信息 要byte数组
        System.out.println("成功");

    }

}
